<?php


namespace app\admin\model;


use think\Model;

class StaffReplyCount extends Model
{
    protected $autoWriteTimestamp = true;

    public static function saveReply($staffNo,$userNo,$re)
    {
        $time = strtotime(date("Y-m-d"));
        $res = StaffReplyCount::where("staff_no",$staffNo)
            ->where("user_no",$userNo)
            ->where("create_day",$time)
            ->find();
        if(!$res){
            StaffReplyCount::create(
                ["staff_no"=>$staffNo,"user_no"=>$userNo,"create_day"=>$time]
            );
            return "";
        }
        // 回复
        if ($res["reply"] == 0 && $re){
            StaffReplyCount::where("id",$res["id"])->data(["reply"=>1])->update();
        }
        return "";
    }
}